﻿
using System;
using System.Text;
using System.Windows.Forms;

namespace GuidGenerator
{
	/// <summary>
	/// Description of GUID Generator.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		void BtnExitClick(object sender, EventArgs e)
		{
			Application.Exit();
		}
		
		void BtnGenerateClick(object sender, EventArgs e)
		{
			decimal numberOfGuids = guidLimit.Value;
			
			var outputString = new StringBuilder();
			
			if (numberOfGuids > 0)
			{
				for (int counter = 0; counter < numberOfGuids; counter++)
				{					
					outputString.Append(Guid.NewGuid().ToString()).Append(Environment.NewLine);
					System.Threading.Thread.Sleep(2);
				}
				
				txtGeneratedValues.Text = outputString.ToString();				
			}
			else
			{
				MessageBox.Show("Number of GUIDs should be >= 1");				
			}
		}
		
		void BtnCopyToClipboardClick(object sender, EventArgs e)
		{
			if(!string.IsNullOrWhiteSpace(txtGeneratedValues.Text))
		  	{
				Clipboard.Clear();
				Clipboard.SetText(txtGeneratedValues.Text);
				MessageBox.Show("Copied GUIDs to clipboard");		
			}
			else
			{
				MessageBox.Show("Nothing to Copy");						
			}
		}
		
		void BtnGenerateAgainClick(object sender, EventArgs e)
		{
			txtGeneratedValues.Text = string.Empty;
			BtnGenerateClick(sender,e);			
		}

	}
}
